package com.daoyin.ssph.frontAction;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

import com.daoyin.ssph.bean.Caselist;
import com.daoyin.ssph.service.CaselistService;
import com.daoyin.ssph.tools.MyPagination;


public class CaselistAction {
	private CaselistService ca;

	public void setCa(CaselistService ca) {
		this.ca = ca;
	}
	private String id;
	public void setId(String id) {
		this.id = id;
	}

	
	public String show(){
		HttpServletRequest request = ServletActionContext.getRequest();
		MyPagination pagination = new MyPagination();
		List<Caselist> list = ca.query();
		for(int i = 0; i < list.size(); i++){
			if(list.get(i).getPublish() == 0){
				list.remove(i);
			}
		}
		String str=(String)request.getParameter("Page");
		int p=1;
		list=pagination.getInitPage(list,1,6);
		p=pagination.getPage(str);
		list=(ArrayList)pagination.getAppointPage(p);
		String pages = pagination.printCtrl(p);
		request.setAttribute("pages", pages);
		request.setAttribute("show", list);
		return "success";

	}
	public String showDetails(){
		HttpServletRequest request = ServletActionContext.getRequest();
		if(Integer.parseInt(id) == 0){
			List<Caselist> list = ca.query();
			for(int i = 0; i < list.size(); i++){
				if(list.get(i).getPublish() == 0){
					list.remove(i);
				}
			}
			if(list.size() == 0){
				request.setAttribute("deltails", "null");
				return "success";
			}else{
				request.setAttribute("deltails", list.get(0));
				return "success";
			}
		}else{
			Caselist caselist = ca.query(Integer.parseInt(id));
			request.setAttribute("deltails", caselist);
			return "success";
		}
	}

}
